// ****************************************************************
// Project7ADriver.java
// ****************************************************************
import java.util.Scanner;
import java.io.*;

public class Project7ADriver {
  public static void main(String[] args) throws IOException {
    // Start Scanner to take user input
    // Scanner scan = new Scanner(System.in);
    // request input file name
    System.out.println("What is the name of the input file? ");
    // String fileName = scan.next();
    // create file scanner
    Scanner fileScan = new Scanner(new File(
          "C:\\Users\\Adam\\Documents\\Northeastern\\Eclipse\\alphaWorkspace\\Wombat\\src\\input.txt"));
    // scanner for each line
    Scanner line = new Scanner(fileScan.nextLine());
    // first 2 inputs of file should be Sport Stacker name and number
    // of times for competition
    // stacker name
    String stackerName = line.nextLine();
    // number of times to be recorded
    line = new Scanner(fileScan.nextLine());
    int numTimes = line.nextInt();
    // create sport stacker
    SportStacker stacker = new SportStacker(stackerName, numTimes);
    // initialize input choice
    int inputChoice = 0;
    // go through rest of input as long as inputs are available or in
    // case user wants to quit (option 6)
    while (fileScan.hasNext() && inputChoice != 6) {
      line = new Scanner(fileScan.nextLine());
      inputChoice = line.nextInt();
      menuSwitch(inputChoice, stacker, line);
    }
  }
  
  public static void menuSwitch(int choice, SportStacker stacker, Scanner line) {
    switch (choice) {
    // print out times
    case 1:
      System.out.println("\n(Option 1) - Print Stacker times");
      System.out.println(stacker.toString());
    break;
    // add value
    case 2:
      System.out.println("\n(Option 2) - Add time");
      double tmp = line.nextDouble();
      stacker.addTime(tmp);
      System.out.println("Time added: " + tmp);
      // Exit
    break;
    // remove slowest
    case 3:
      System.out.println("\n(Option 3) - Remove slowest time");
      stacker.removeSlowestTime();
      System.out.println("Done");
    break;
    // find fastest time
    case 4:
      System.out.println("\n(Option 4) - Compute fastest time");
      System.out.println("The fastest time is: " + stacker.computeFastestTime());
    break;
    // compute average time
    case 5:
      System.out.println("\n(Option 5) - Compute average time");
      System.out.println("The average time is: " + stacker.computeAvgerageTime());
    break;
    // exit
    case 6:
      System.out.println("\n(Option 6) - Exit\nGoodbye!");
    break;
    // if invalid choice
    default:
      System.out.println("\nSorry, invalid choice");
    break;
    }
  }
}
